/**
 * 
 */
package net.homelinux.ajay.net.ondisk.view.menu.client;

import net.homelinux.ajay.net.ondisk.view.client.AppTree;
import net.homelinux.ajay.net.ondisk.view.client.CommandsMenu;
import net.homelinux.ajay.net.ondisk.view.client.FolderTreeItem;
import net.homelinux.ajay.net.ondisk.view.client.NamedCommand;
import net.homelinux.ajay.net.ondisk.view.dialogs.client.AddFolderDialog;
import net.homelinux.ajay.net.ondisk.view.dialogs.client.AddLinksDialog;
import net.homelinux.ajay.net.ondisk.view.dialogs.client.AppDialogBox;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Tree;

/**
 * @author ajay
 *
 */
public class FolderMenuBuilder extends MenuBuilder {

  private static FolderMenuBuilder instance;

  public CommandsMenu makeContextMenu()
  {
    CommandsMenu contextMenu = super.makeContextMenu();
    if(contextMenu==null){
      contextMenu = new CommandsMenu();
    }
    contextMenu.addCommand(new NamedCommand("Add Folder",null){

      public void execute() {
        System.out.println("Executing Named Command :"+ getName());
        FolderTreeItem parent = (FolderTreeItem) getTree().getSelectedItem();
        AddFolderDialog.makeDialog().show(parent);
      }});
    
    contextMenu.addCommand(new NamedCommand("Add Link(s)", null){

      public void execute() {
        System.out.println("Executing Named Command :"+ getName());
//        FolderTreeItem parent = (FolderTreeItem) getTree().getSelectedItem();
        AddLinksDialog.makeAddLinksDialog().show();
      }});
    
    contextMenu.addCommand(new NamedCommand("<hr/>", null){

      public void execute() {
        // NOOP
        
      }});
    contextMenu.addCommand(getDeleteCommand());
    return contextMenu;
    
  }

  protected NamedCommand getDeleteCommand() {
    return new NamedCommand("Delete Folder", null){

      public void execute() {
        System.out.println("Executing Named Command :"+ getName());
        FolderTreeItem current = (FolderTreeItem) getTree().getSelectedItem();
        current.removeFolderFromParent();
        
      }};
  }

  public static FolderMenuBuilder getInstance() {
    if(instance == null){
      instance = new FolderMenuBuilder();
    }
    return instance;
  }

}
